#ifndef _ANIMATION_H_
#define _ANIMATION_H_

#include "Animator.h"
#include "../../includes/includes.h"

//=============================================================================
/** This is an extended Animation base with built
	in support for 'progress' based calculation
	and looping. */
class TimedAnimation	:	public Animation
{
public:

	TimedAnimation (void* animTarget, const String& name, const String& type);
	virtual ~TimedAnimation ();

	void setSpeed (double newSpeed);
	double getSpeed ();
	void setDuration (int ms);
	int getDuration ();

	/** Set whether or not this animation should loop. If
		shouldPingPong is true, then the animation will
		move backwards when it reaches the end (a single
		cycle then ends when it returns to the start).
		If numTimes is 0, it will loop forever. */
	void setLooping (bool shouldLoop, bool shouldPingPong = false, int numTimes = 0);
	bool isLooping ();
	bool isPingPong ();

	bool useTimeSlice (const int elapsed);

	/** This is where you define the animation, in terms
		of a progress parameter (from 0 to 1). */
	virtual void update (double progress) = 0;

	void skipToEnd ();
	void resetToStart ();

private:

	bool looping;
	bool pingPong;
	bool forwards;

	int loopCount;
	int numLoops;

	double speed;
	int duration;
	double currentProgress;
	int pos;

};

//=============================================================================
// TimedAnimation-based animation base classes
//=============================================================================
class LinearXYAnimation	:	public TimedAnimation
{
public:

	LinearXYAnimation (void* animTarget, const String& name, const String& type, int startX, int startY, int finishX, int finishY, int durationMs);
	~LinearXYAnimation ();

	void update (double progress);
	/** Use this function to apply the two parameters
		to the target. */
	virtual void applyUpdateToTarget (int x, int y) = 0;

private:

	int x1, y1, x2, y2;
};

//-------------------------------------
class LinearDoubleAnimation	:	public TimedAnimation
{
public:

	LinearDoubleAnimation (void* animTarget, const String& name, const String& type, double start, double finish, int durationMs);
	~LinearDoubleAnimation ();

	void update (double progress);
	/** Use this function to apply the parameter to
		the target. */
	virtual void applyUpdateToTarget (double value) = 0;

private:

	double vstart, vend;
};

//-------------------------------------
class LinearColourAnimation	:	public TimedAnimation
{
public:

	LinearColourAnimation (void* animTarget, const String& name, const String& type, const Colour& startColour, const Colour& endColour, int durationMs);
	~LinearColourAnimation ();

	void update (double progress);
	/** Use this function to apply the current colour
		to the target. */
	virtual void applyUpdateToTarget (const Colour& currentColour) = 0;

private:
	Colour c1;
	Colour c2;
};

//=============================================================================

#endif//_ANIMATION_H_
